<template>
  <div>
    <div class="wrap">
      <div class="title">编辑推荐</div>
      <div class="content">
        <van-row gutter="4">
          <van-col span="8" v-for="item in list" :key="item.id">
            <div class="item">
              <router-link :to="'/playlist/' + item.id">
                <img :src="item.picUrl" alt="" />
                <div class="total">
                  <img src="@/assets/images/headset.png" />{{
                    num(item.playCount)
                  }}
                </div>
                <div class="info">{{ item.name }}</div></router-link
              >
            </div>
          </van-col>
        </van-row>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="main">
      <div class="title">最新音乐</div>
      <div class="list">
        <div v-for="item in newSong" :key="item.id">
          <!-- {name:'songpage',params:{id:item.id,name:item.name}}" -->
          <div @click="ToSongPage(item)" class="song">
            <div class="left">
              <div class="subtitle">
                {{ item.name }}
                <span> {{ item.song.alias[0] }} </span>
              </div>
              <div class="author">
                <span
                  class="auts"
                  v-for="(aut, index) in item.song.artists"
                  :key="aut.id"
                  >{{ aut.name
                  }}{{
                    item.song.artists.length - 1 === index ? "" : " / "
                  }}</span
                >
                <span>-{{ item.song.album.name }}</span>
             </div>
            </div>
            <div class="right">
              <img src="@/assets/images/play.png" alt="" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Music",
  data() {
    return {
      list: [],
      newSong: [],
      // autTotal:[],
    };
  },
  //进入页面获取网络请求---生命周期函数
  created() {
    this.getMusics();
    this.getNewSong();
  },
  methods: {
    async getMusics() {
      let res = await this.$api.getMusic();
      // console.log(res);
      this.list = res.data.result;
      // console.log(this.list);
    },
    num(n) {
      if (!n) return;
      n = n > 9999 ? (n / 10000).toFixed(1) + "万" : n;
      return n;
    },
    async getNewSong() {
      let val = await this.$api.getSong();
      this.newSong = val.data.result;
      console.log(this.newSong);
      // this.autTotal=this.newSong.map((item)=>{
      //   return item.song.artists.map(items=>{
      //     return items.name;
      //   })
    },
    ToSongPage(val){
      console.log(val);
      this.$router.push({
        name:'songpage',
        params:
        {id:val.id,title:val.name}
      })
    }
  },
};
</script>

<style lang="less" scoped>
.title {
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
  font-size: 0.34rem;
  position: relative;
  padding-left: 0.2rem;
  &::before {
    content: "";
    position: absolute;
    width: 2px;
    height: 20px;
    top: 2px;
    background: #ff5555;
    left: 0;
  }
}
.content {
  .item {
    position: relative;
    img {
      width: 100%;
      height: 2.448rem;
    }
    .total {
      position: absolute;
      top: 2px;
      right: 2px;
      color: #fff;
      img {
        width: 0.3rem;
        position: absolute;
        top: 0.08rem;
        left: -0.34rem;
      }
    }
    .info {
      margin: 0.14rem;
      text-overflow: elllipsis;
      overflow: hidden;
      font-size: 0.26rem;
      color: #333;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }
  }
  .val-col {
    height: 3.42rem;
  }
}
.song {
  padding-top: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eee;
  padding-left: 0.2rem;
  display: flex;
  .left {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
  }
  .right {
    width: 0.84rem;
    display: flex;
    justify-items: center;
    align-items: center;
    img {
      width: 0.6rem;
      height: 0.6rem;
    }
  }
  .subtitle {
    font-size: 0.34rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;

    span {
      color: #888;
    }
  }
  .author {
    margin-top: 4px;
    font-size: 12px;
    color: #888;

    // .auts {
    //   &::after {
    //     content: " / ";
    //   }
    // }
    // .auts:last-child {
    //         &::after {
    //             content: "";
    //         }
    //     }
  }
}
</style>
